<template>
	<view class="index">
		<view class="tab">
			<u-tabs 
				:list="tabs" 
				:current="tabCurrent"
				:is-scroll="false"
				bar-height="2"
				bar-width="88"
				inactive-color="#030303"
				active-color="#030303"
				:bar-style="{
					backgroundColor: '#FFC046'
				}"
				@change="changeTab"
			></u-tabs>
		</view>
		<view class="swiper">
			<swiper 
				:indicator-dots="false" 
				:current="tabCurrent" 
				:autoplay="false" 
				:interval="1500" 
				:duration="500"
				@change="changeSwiper"
				:style="{
					height: swiperHeight + 'px'
				}"
				ref="swiper"
			>
				<swiper-item>
					<view class="component">
						
					</view>
				</swiper-item>
				<swiper-item>
					<u-parse :html="item.content" class="component"></u-parse>
				</swiper-item>
			</swiper>
		</view>
		<view id="test">
			
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				tabCurrent: 0,
				tabs: [
					{name: '评价(1555)'},
					{name: '商品详情'}
				],
				swiperHeight: 0
			};
		},
		methods: {
			changeTab(index){
				this.tabCurrent = index
			},
			changeSwiper({detail: {current}}){
				this.tabCurrent = current
				this.setSwiperHeight()
			},
			setSwiperHeight(){
				uni.createSelectorQuery().in(this)
				.selectAll('.swiper .component')
				.boundingClientRect(data=>{
					this.swiperHeight = data[this.tabCurrent].height
				}).exec()
			}
		},
		mounted() {
			this.setSwiperHeight()
		}
	}
</script>

<style lang="scss" scoped>
	.index{
		margin-top: $uni-spacing-col-base;
		padding: 0 $uni-spacing-row-base;
		background-color: $uni-bg-color;
		.swiper{
			min-height: 300upx;
			margin-top: $uni-spacing-col-base;
		}
	}
</style>
